/*
Package service
@Time : 2022/12/21 16:31
@Author : 董胜烨
@File : attendance
@Software: GoLand
@note:
*/
package service

import (
	"employee/model"
	"fmt"
)

type Attendance struct {
	Date       string `json:"date"`
	EmployeeID int64  `json:"employee_id"`
	ID         int64  `json:"id"`
	Type       int64  `json:"type"`
}

func (a *Attendance) Insert() bool {
	sqlStr := "INSERT INTO attendance (employee_id, date, type) VALUES (?,?,?) "
	insertID := model.Insert(sqlStr, a.EmployeeID, a.Date, a.Type)
	if insertID == 0 {
		return false
	}
	a.ID = insertID
	return true
}

func (a Attendance) Update() bool {
	sqlStr := "UPDATE attendance SET employee_id=?,date=?,type=? WHERE id=?"
	ok := model.Update(sqlStr, a.EmployeeID, a.Date, a.Type, a.ID)
	return ok
}

func (a Attendance) Delete() bool {
	sqlStr := "DELETE FROM attendance WHERE id=?"
	ok := model.Delete(sqlStr, a.ID)
	return ok
}

func (a Attendance) QueryByEmployeeId() []map[string]string {
	sqlStr := fmt.Sprintf("SELECT * FROM attendance WHERE employee_id='%d'", a.EmployeeID)
	res := model.QueryAll(sqlStr)
	if res != nil {
		return res
	}
	return nil
}
